<style lang="scss">
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "uview-ui/index.scss";
</style>
<script>
	/**
	 * vuex管理登陆状态，具体可以参考官方登陆模板示例
	 */
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		methods: {
			...mapMutations(['login']),
			loadLogin() {
				console.log(uni.getStorageSync('userToken'))
				let tokenId = uni.getStorageSync('userToken');
				let userUuid = uni.getStorageSync("userInfo").userUuid
				console.log('_______________' + tokenId)
				if (tokenId) {
					//使用token就可以查询用户信息
					this.$api.request.userInfoAndAreaInfo({
						tokenId: tokenId,
						userUuid: userUuid
					}, loginRes => {
						if (loginRes && loginRes.body.status.statusCode == '0') {
							let provider = loginRes.body.data
							this.login(provider)
						} else {
							console.log('同步用户信息失败, tokenId: ' + tokenId);
						}
					});
				}
			},
			// 全局请求方法
			 request(){
				return new Promise((resolve,reject)=>{
					uni.request({
						method:'GET',
						// 需要接口地址
						url:'',
						success: (res) => {
							resolve(res)
						},
						fail: (err) => {
							reject(err)
						}
					})
				})
			}
		},
		computed: {
			...mapState(['hasLogin', 'userInfo', 'hasOwner']),
		},
		onLaunch: function() {
			console.log("showAPP")
			// 缓存微信appId
			// const accountInfo = wx.getAccountInfoSync();
			// let appId = accountInfo.miniProgram.appId;
			// let appId ='wxa01ba442d5550a91'
			// uni.setStorageSync("appId", appId);
			
			//设置竖屏
			// #ifdef APP-PLUS
			plus.screen.lockOrientation('portrait-primary');
			// #endif

			this.loadLogin()
		},
		onShow: function() {
			uni.hideTabBar()
			let params = {
				"type": "手机端登录", //森林防火报警、人流告警、事件上报、手机端登录（当天第一次进入首页）  type 1  2   3  4
				"areaCode": this.$api.request.communityCode,
				"alarmInfo": "手机端登录",
			}

			uni.request({
				url: this.$api.request.apiBaseUrl + "lezhiDevice/deviceAlarmPush",
				data: params,
				method: 'POST',
				success: (response) => {}
			})
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style lang='scss'>
	@import './static/css/style.css';
	@import './static/css/iconfont.css';
	@import './static/css/aliiconfont.css';
	@import url('./static/css/parse.css');

	/* 图片载入替代方案 */
	.image-wrapper {
		font-size: 0;
		background: #f3f3f3;
		border-radius: 4px;

		image {
			width: 100%;
			height: 100%;
			transition: .6s;
			opacity: 0;

			&.loaded {
				opacity: 1;
			}
		}
	}

	/* #ifdef H5 */
	uni-page-head {
		display: none;
	}

	/* #endif */

</style>
